package edu.sctu.practice.class01.zhengsenwen.assign.assign04;

/**
 * Created by zhengsenwen on 2015/12/17.
 */
public class StringDemo {

//    1、编写一个Java应用程序，判断两个字符串是否相同，
//    判断字符串的前缀、后缀是否和某个字符串相同，
//    按字典顺序比较两个字符串的大小关系，
//    检索字符串
// ，创建字符串，将数字型字符串转换为数字，将字符串存放到数组中，用字符数组创建字符串。

    public String isEqual(String string1, String string2) {
        if (string1 == string2) {
            return string1 + "和" + string2 + "相同";
        } else {
            return string1 + "和" + string2 + "不同";
        }
    }


    public String isStartEqual(String string1, String string2) {
        if (string1.startsWith(string2)) {
            return string1 + "的前缀是" + string2;
        } else {
            return string1 + "的前缀不是" + string2;
        }
    }

    public String isEndEqual(String string1, String string2) {
        if (string1.endsWith(string2)) {
            return string1 + "的后缀是" + string2;
        } else {
            return string1 + "的后缀不是" + string2;
        }
    }

    public String compareInDictionary(String string1, String string2) {
        if (string1.compareTo(string2) < 0) {
            return string1 + "在字典中的顺序大于" + string2;
        } else if (string1.compareTo(string2) == 0) {
            return string1 + "在字典中的顺序等于" + string2;
        } else {
            return string1 + "在字典中的顺序小于" + string2;
        }
    }


    public void searchString(String string1, String string2) {
        System.out.println(string1.indexOf(string2));
    }

    public void stringToIntager(String string1, String string2) {
        int num1 = Integer.parseInt(string1);
        int num2 = Integer.parseInt(string2);
        System.out.println(num1);
        System.out.println(num2);
    }

    public void arrayToString(String string) {
        char[] arr = string.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }

    public static void main(String[] args) {
        StringDemo stringDemo = new StringDemo();
        System.out.println(stringDemo.isEqual("Hello,my world!", "Hello,my dear!"));
        System.out.println(stringDemo.isStartEqual("Hello,my world!", "Hello"));
        System.out.println(stringDemo.isEndEqual("Hello,my world!", "dear!"));
        System.out.println(stringDemo.compareInDictionary("Hello,my world!", "Hello,my dear!"));
        stringDemo.searchString("Hello,my world!", "my");
        stringDemo.stringToIntager("111", "345");
        stringDemo.arrayToString("Hello,my world!");
    }
}
